--编写者：alt
--功能介绍：旺达的部分能力
--使用方法：直接粘贴 修改herta为玩家对应prefab

--旺达的部分能力
local function onbecamehuman(inst, data, isloading)
    if inst.components.positionalwarp ~= nil then
        if not isloading then
            inst.components.positionalwarp:Reset()
        end
        if inst.components.inventory:HasItemWithTag("pocketwatch_warp", 1) then
            inst.components.positionalwarp:EnableMarker(true)
        end
    end
end

local function onbecameghost(inst, data)
    if inst.components.positionalwarp ~= nil then
        inst.components.positionalwarp:EnableMarker(false)
    end
end
local function on_show_warp_marker(inst)
    inst.components.positionalwarp:EnableMarker(true)
end

local function on_hide_warp_marker(inst)
    inst.components.positionalwarp:EnableMarker(false)
end
local function OnWarpBack(inst, data)
    if inst.components.positionalwarp ~= nil then
        if data ~= nil and data.reset_warp then
        else
            inst.components.positionalwarp:GetHistoryPosition(true)
        end
    end
end
local wandaab = function(inst)
    --旺达的部分能力
    inst:AddTag("pocketwatchcaster")
    if not TheWorld.ismastersim then
        return
    end
    inst:AddComponent("oldager")
    inst.components.oldager:AddValidHealingCause("pocketwatch_heal")
    inst.components.oldager:AddValidHealingCause("debug_key")
    inst.components.oldager.base_rate = 0

    inst:AddComponent("positionalwarp")
    inst:DoTaskInTime(0, function() inst.components.positionalwarp:SetMarker("pocketwatch_warp_marker") end)
    inst.components.positionalwarp:SetWarpBackDist(TUNING.WANDA_WARP_DIST_NORMAL)

    inst:ListenForEvent("show_warp_marker", on_show_warp_marker)
    inst:ListenForEvent("hide_warp_marker", on_hide_warp_marker)

    inst:ListenForEvent("onwarpback", OnWarpBack)

    inst:ListenForEvent("ms_respawnedfromghost", onbecamehuman)
    inst:ListenForEvent("ms_becameghost", onbecameghost)
    if inst:HasTag("playerghost") then
        onbecameghost(inst)
    elseif inst:HasTag("corpse") then
        onbecameghost(inst, { corpse = true })
    else
        onbecamehuman(inst, nil, true)
    end
end
AddPrefabPostInit("herta", wandaab)